package cn.biplam.front.template.control;

import cn.biplam.common.wrapper.ErrorMessage;
import cn.biplam.front.html.HtmlDiv;
import cn.biplam.front.html.HtmlImage;
import cn.biplam.front.html.HtmlText;
import cn.biplam.front.html.base.Html;
import cn.biplam.front.html.base.HtmlWindow;
import cn.biplam.front.html.base.Const.Float_Type;
import cn.biplam.front.template.Template;

/**
 * 	生成滑动菜单的节点文本内容
 * @author 	WangSong
 * @create 	2009-5-29 上午11:50:31
 * @version 1.0
 */
public class PicText implements Template{
	
	private HtmlWindow picText;
	private HtmlWindow pic;
	private HtmlText mText;
	private int length=0;
	private String text;
	private String sHomeUrl;
	private String picPath;
	
	/**
	 * 构造方法
	 * @param text      节点文本内容
	 * @param sHomeUrl  系统路径
	 * @param picPath   图片的路径
	 * @throws ErrorMessage
	 */
	public PicText(String text,String sHomeUrl,String picPath) throws ErrorMessage{
		this(text,null,sHomeUrl,picPath);
	}
	
	/**
	 * 构造方法
	 * @param text   节点文本内容
	 * @param ID     唯一标识ID
	 * @param sHomeUrl  系统路径
	 * @param picPath   图片的路径
	 * @throws ErrorMessage
	 */
	public PicText(String text,String ID,String sHomeUrl,String picPath) throws ErrorMessage{
		this.mText=new HtmlText(ID+"t","sleekpt");
		this.picText = new HtmlDiv(ID,"sleeks");
		this.pic = new HtmlDiv(ID+"p");
		this.text = text;
		this.sHomeUrl = sHomeUrl;
		this.picPath = picPath; 
	}
	
	/**
	 * 功能：放入文本
	 * @param sText
	 */
	private void put(String sText){
		this.mText.put(sText);
		this.length=mText.length()+18;
	}
	
	/**
	 * 功能 获取文本字符长度
	 * @return
	 */
	public int getLength(){
		return this.length;
	}
	
	/**
	 * 功能 放入html对象(放入的对象必须设置好对齐方式)
	 * @param html
	 * @throws ErrorMessage
	 */
	public void put(Html html) throws ErrorMessage{
		this.put(html);
	}
	
	/**
	 * 功能：返回设置好的HtmlWindow对象
	 * @return
	 * @throws ErrorMessage 
	 */
	public HtmlWindow get() throws ErrorMessage{
		put(text);
		this._getPic(picPath, sHomeUrl);
		this.picText.put(this.pic);
		this.picText.put(this.mText);
		return this.picText;
	}
	
	/**
	 * 取图片div
	 * @param picPath 图片路径
	 * @throws ErrorMessage 
	 */
	private void _getPic(String picPath,String sHomeUrl) throws ErrorMessage{
		this.pic.setFloat(Float_Type.Left);
		if(picPath!=null && picPath.indexOf("/")==-1){
			picPath = "/"+picPath;
		}
		HtmlImage mImage=new HtmlImage(this.sHomeUrl+picPath,"tismall");
		this.pic.put(mImage);
	}
}
